package cn.edu.wynu.testdynamic;

import cn.edu.wynu.mapper.StudentMapper;
import cn.edu.wynu.pojo.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class DynamicChooseLearn {
    public static void main(String[] args) throws IOException {
        InputStream resource = Resources.getResourceAsStream("mybatis-config.xml");

        // 指定环境名
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(resource, "school");
        SqlSession sqlSession = sessionFactory.openSession();
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);

        List<Student> students = mapper.dynamicSelectChoose(null, null);
        System.out.println(students);

        List<Student> students1 = mapper.dynamicSelectChoose(3, null);
        System.out.println(students1);

        List<Student> students2 = mapper.dynamicSelectChoose(3, "女");
        System.out.println(students2);

        List<Student> mans = mapper.dynamicSelectChoose(null, "男");
        System.out.println(mans);
        sqlSession.close();
    }
}
